<template>
<div>
  <h1>兑换礼品</h1>
  <h2>我的积分有{{list1.jf}}</h2>
  <table border="1" cellpadding="0">
    <tr>
      <td>礼品</td>
      <td>需要积分</td>
      <td>库存</td>
      <td>操作</td>
    </tr>
    <tr v-for="i in list" :key="i">
      <td>{{i.name}}</td>
      <td>{{ i.jf }}</td>
      <td>{{i.kucun}}</td>
      <td>
        <van-button @click=" add(i.id)">兑换</van-button>
      </td>
    </tr>

  </table>
</div>
</template>

<script>
import maxios from "../../http/axios";

export default {
  name: "lip",
  data(){
    return{
      list:[],
      user:localStorage.getItem('userid'),
      list1:[]
    }
  },
  methods:{
    show(){
      maxios('http://127.0.0.1:8000/users/Xiaoshuo/','get')
      .then(i=>{
        this.list = i.data.list
      })
    },
    show_user(){
      maxios('http://127.0.0.1:8000/users/Alogin/?id='+this.user,'get')
      .then(i=>{
        this.list1 = i.data.list
      })
    },
    add(id){
      maxios('http://127.0.0.1:8000/users/Add_lip/','post',{user:this.user,liping:id})
      .then(i=>{
        if (i.data.code ==200){
          alert('兑换成功')
          this.show()
          this.show_user()
        }
        else {
          alert(i.data.mes)
        }
      })
    }
  },
  mounted() {
    this.show()
    this.show_user()
  }
}
</script>

<style scoped>

</style>